package com.dower.clothing.controller;

import java.util.List;

import com.dower.clothing.service.IFinaPurchaseGoodsService;
import com.dower.common.annotation.Log;
import com.dower.common.core.controller.BaseController;
import com.dower.common.core.domain.AjaxResult;
import com.dower.common.core.page.TableDataInfo;
import com.dower.common.enums.BusinessType;
import com.dower.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.dower.clothing.domain.FinaPurchaseStatistics;
import com.dower.clothing.service.IFinaPurchaseStatisticsService;

/**
 * 进货统计Controller
 * 
 * @author dower
 * @date 2020-09-02
 */
@Controller
@RequestMapping("/clothing/finapurchasestatistics")
public class FinaPurchaseStatisticsController extends BaseController
{
    private String prefix = "clothing/finapurchasestatistics";
    @Autowired
    private IFinaPurchaseGoodsService finaPurchaseGoodsService;
    @Autowired
    private IFinaPurchaseStatisticsService finaPurchaseStatisticsService;

    @RequiresPermissions("clothing:finapurchasestatistics:view")
    @GetMapping()
    public String FinaPurchaseStatistics()
    {
        return prefix + "/finapurchasestatistics";
    }

    /**
     * 查询进货统计列表
     */
    @RequiresPermissions("clothing:finapurchasestatistics:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FinaPurchaseStatistics finaPurchaseStatistics)
    {
        startPage();
        List<FinaPurchaseStatistics> list = finaPurchaseStatisticsService.selectFinaPurchaseStatisticsList(finaPurchaseStatistics);
        return getDataTable(list);
    }

    /**
     * 导出进货统计列表
     */
    @RequiresPermissions("clothing:finapurchasestatistics:export")
    @Log(title = "进货统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FinaPurchaseStatistics finaPurchaseStatistics)
    {
        List<FinaPurchaseStatistics> list = finaPurchaseStatisticsService.selectFinaPurchaseStatisticsList(finaPurchaseStatistics);
        ExcelUtil<FinaPurchaseStatistics> util = new ExcelUtil<FinaPurchaseStatistics>(FinaPurchaseStatistics.class);
        return util.exportExcel(list, "finapurchasestatistics");
    }

    /**
     * 新增进货统计
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        mmap.put("finaPurchaseGoodsList", finaPurchaseGoodsService.selectFinaPurchaseGoodsList(null));
        return prefix + "/add";
    }

    /**
     * 新增保存进货统计
     */
    @RequiresPermissions("clothing:finapurchasestatistics:add")
    @Log(title = "进货统计", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FinaPurchaseStatistics finaPurchaseStatistics)
    {
        return toAjax(finaPurchaseStatisticsService.insertFinaPurchaseStatistics(finaPurchaseStatistics));
    }

    /**
     * 修改进货统计
     */
    @GetMapping("/edit/{purchaseStatisticsId}")
    public String edit(@PathVariable("purchaseStatisticsId") Long purchaseStatisticsId, ModelMap mmap)
    {
        FinaPurchaseStatistics finaPurchaseStatistics = finaPurchaseStatisticsService.selectFinaPurchaseStatisticsById(purchaseStatisticsId);
        mmap.put("finaPurchaseStatistics", finaPurchaseStatistics);
        return prefix + "/edit";
    }

    /**
     * 修改保存进货统计
     */
    @RequiresPermissions("clothing:finapurchasestatistics:edit")
    @Log(title = "进货统计", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FinaPurchaseStatistics finaPurchaseStatistics)
    {
        return toAjax(finaPurchaseStatisticsService.updateFinaPurchaseStatistics(finaPurchaseStatistics));
    }

    /**
     * 删除进货统计
     */
    @RequiresPermissions("clothing:finapurchasestatistics:remove")
    @Log(title = "进货统计", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(finaPurchaseStatisticsService.deleteFinaPurchaseStatisticsByIds(ids));
    }
}
